package com.liugege.make.singleton;
/**
* @author: LiuGeGe
* @Date: 2022/3/2 15:51
* @Description(类描述):  懒汉  单例设计模式  存在线程安全问题
* @Class(类): SingletonDemo2
*/
public class SingletonDemo2 {
    private  static SingletonDemo2 singletonDemo2 = null;
    private  SingletonDemo2(){
        System.out.println("懒汉式");
    }
    public static SingletonDemo2 getInstance(){
        //System.out.println("在这里加载了");
        if (singletonDemo2 == null){
            singletonDemo2 = new SingletonDemo2();
        }
        return singletonDemo2;
    }
    public static synchronized SingletonDemo2 getInstance2(){
        //System.out.println("在这里加载了");
        if (singletonDemo2 == null){
            singletonDemo2 = new SingletonDemo2();
        }
        return singletonDemo2;
    }

    public static void main(String[] args) {
        SingletonDemo2 instance1 = SingletonDemo2.getInstance2();
        SingletonDemo2 instance2 = SingletonDemo2.getInstance2();
        System.out.println(instance1.hashCode());
        System.out.println(instance2.hashCode());
    }
}
